home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / printer / prntchar.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  2.5 KB  |  96 lines

  1. ;void  print_char(ch,number);
  2. ;  char  ch;
  3. ;  unsigned short  number;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.     EXTRN  _time_out:byte
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME  CS:_TEXT
  11.     PUBLIC  _print_char
  12. _print_char proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;
  15.     push si            ;
  16.     cmp  _memory_model,0    ;near or far?
  17.     jle  begin        ;jump if near
  18.     inc  bp            ;else add 2 to BP
  19.     inc  bp            ;
  20. begin:    mov  _error_code,1    ;1 = printer error
  21.     mov  ah,1        ;BIOS func to init prtr
  22.     mov  dx,0        ;choose LPT1
  23.     int  17h        ;initialize the prtr port
  24.     sub  ax,ax        ;clear AX
  25.     mov  es,ax        ;pt ES to 0000:0000
  26.     mov  dx,es:[408H]    ;get LPT1 base address
  27.     sub  cx,cx        ;clear CX
  28.     mov  cl,[bp+6]        ;number chars (255 limit)
  29.     jcxz L3            ;quit if 0
  30.     mov  al,_time_out    ;get _time_out seconds
  31.     or   al,al        ;don't allow zero
  32.     jnz  L1            ;
  33.     mov  al,3        ;default to 3 seconds
  34. L1:    mov  bl,18        ;18 ticks per second
  35.     mul  bl            ;
  36.     mov  [bp+6],ax        ;save count
  37.     mov  bl,[bp+4]        ;keep char in bl
  38. L2:    mov  al,bl        ;character to AL
  39.     call Writeit        ;
  40.     or   ah,ah        ;test for error
  41.     jz   L3            ;quit if error
  42.     loop L2            ;go write next char
  43.     mov  _error_code,0    ;0 = no error
  44. L3:    pop  si            ;
  45.     pop  bp            ;
  46.     cmp  _memory_model,0    ;quit
  47.     jle  quit        ;
  48.     db   0CBh        ;RET far
  49. quit:    ret            ;RET near
  50. Writeit    PROC
  51.     out  dx,al        ;send to output data register
  52.     inc  dx            ;forward to status register
  53.     push cx            ;save string counter
  54.     call GetBiosCount    ;get timer reading
  55.     mov  si,cx        ;make copy
  56.     add  cx,[bp+6]        ;add delay count
  57.     cmp  si,cx        ;if timer doesn't turn over...
  58.     jb   L4            ;go ahead
  59.     mov  cx,[bp+6]        ;otherwise, extend delay
  60. L4:    mov  [bp+4],cx        ;save target count on stack
  61. Wait:    in   al,dx        ;get status value
  62.     test al,8        ;test for printer error
  63.     jz   Error        ;
  64.     test al,80h        ;test for Printer Ready
  65.     jnz  Ready        ;jump if ready
  66. Error:    call GetBiosCount    ;
  67.     cmp  cx,[bp+4]        ;compare to target
  68.     jb   Wait        ;    
  69.     pop  cx            ;restore string counter
  70.     mov  ah,0        ;return code for failure
  71.     jmp  short L5        ;return
  72. Ready:    pop  cx            ;restore string counter
  73.     inc  dx            ; output control register
  74.     mov  al,13        ;bits for strobe signal
  75.     out  dx,al        ;send the signal
  76.     dec  al            ;change to strobe OFF
  77.     out  dx,al        ;send the signal
  78.     dec  dx            ;point back to
  79.     dec  dx            ;  base address
  80.     mov  ah,1        ;return code for success
  81. L5:    ret              ;
  82. Writeit    endp
  83. GetBIOSCount PROC
  84.     push dx            ;return value in CX:DX
  85.     push ax            ;
  86.     sub  ah,ah        ;function number
  87.     int  1ah        ;get timer count
  88.     mov  cx,dx        ;low word in CX
  89.     pop  ax            ;
  90.     pop  dx
  91.     ret
  92. GetBIOSCount endp
  93. _print_char endp
  94. _TEXT    ENDS
  95.     END
  96.